﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Furiant.Figment.Agents;
using Furiant.Figment.Agents.Inventory;
using Furiant.Figment.Items.Lootable;

namespace Furiant.Figment.Core
{
    public class FigmentData
    {
        #region Singleton

        private static readonly Lazy<FigmentData> lazy =
        new Lazy<FigmentData>(() => new FigmentData());

        public static FigmentData Instance { get { return lazy.Value; } }

        private FigmentData() {}

        #endregion

        private int _lastGameObjectId;

        private readonly HashSet<StatDefinition> _statDefinitions = new HashSet<StatDefinition>();

        private readonly HashSet<EquipSlotDefinition> _equipSlotDefinitions =
            new HashSet<EquipSlotDefinition>();


        public int LastGameObjectId { get { return _lastGameObjectId; } }

        public IEnumerable<StatDefinition> StatDefinitions { get { return _statDefinitions; } }

        public IEnumerable<EquipSlotDefinition> EquipSlotDefinitions { get { return _equipSlotDefinitions; } }


        public StatDefinition RegisterStatDefinition(string identifier, string name, string abbreviation, string description)
        {
            var stat = new StatDefinition(identifier, name, abbreviation, description);

            _statDefinitions.Add(stat);

            return stat;
        }

        public EquipSlotDefinition RegisterEquipSlotDefinition(string identifier, string name, string description)
        {
            var slot = new EquipSlotDefinition(identifier, name, description);

            _equipSlotDefinitions.Add(slot);

            return slot;
        }

        
        internal int GenerateGameObjectId(IGameObject item)
        {
            if (item.Id != 0)
            {
                throw new ArgumentException("Item already has an Id.");
            }

            _lastGameObjectId++;

            return _lastGameObjectId;
        }
    }
}
